#include <iostream>
#include <vector>

using namespace std;

int calculatePoints(vector<string>& target) {
    int points = 0;
    int multipliers[5] = { 1, 2, 3, 4, 5 };

    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            if (target[i][j] == 'X') {
                int ring = min(min(i, j), min(9 - i, 9 - j));
                points += multipliers[ring];
            }
        }
    }

    return points;
}

int main() {
    int t;
    cin >> t;

    while (t--) {
        vector<string> target(10);
        for (int i = 0; i < 10; i++) {
            cin >> target[i];
        }

        int points = calculatePoints(target);
        cout << points << endl;
    }

    return 0;
}
